package com.xiaopengpeng.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.runners.Parameterized.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xiaopengpeng.service.PeopleService;


@Controller
public class ControllerTest {
	
	/**
	 * requestParam
	 * @Component
	 * @Controller
	 * @Service
	 * @Repository
	 * @Autowired
	 * @Resource
	 * 
	 * @param response
	 * @return
	 */
	
	@Resource(name="peopleService")
	private PeopleService peopleService;
	
	@ResponseBody
	@RequestMapping(value = "/test" ,produces = "application/json; charset=utf-8")
	public String cont(@RequestParam("name") String name,@RequestParam("ag") String age,HttpServletResponse response,HttpServletRequest request){
		//response.setContentType("text/plain;charset=ISO-8859-1");
		response.setContentType("text/plain;charset=UTF-8"); 
		System.out.println("-------------------------");
		System.out.println(name+age);
		String test = peopleService.test();
		System.out.println(test);
		return "you are sesseful 成功";
	}
	@ResponseBody
	@RequestMapping("/test1")
	public String cont1(HttpServletResponse response) throws Exception{
		// 通过加载配置文件获取连接 （添加文件hbase-site.xml）
				Configuration conf = HBaseConfiguration.create();
				Connection connection = null;
				try {
					connection = ConnectionFactory.createConnection(conf);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				// 获取需要操作的表
				Table table = null;
				try {
					table = connection.getTable(TableName.valueOf("t_user"));
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				// put(rowkey)
				Put put = new Put(Bytes.toBytes("rowkey003"));
				put.addColumn(Bytes.toBytes("base_info"), Bytes.toBytes("name"), Bytes.toBytes("pengpeng"));
				put.addColumn(Bytes.toBytes("base_info"), Bytes.toBytes("age"), Bytes.toBytes(18));
				table.put(put);

				table.close();
				connection.close();
		
		return "you are sesseful 成功";
	}
	

}
